﻿using System.Text;

namespace Tab2Sql
{
    internal static class outputAdjustment
    {
        /// <summary>
        /// replaces 'null' with null
        /// </summary>
        /// <param name="inV"></param>
        /// <returns></returns>
        public static string ReplaceLiteralNullsWithNulls(string inV)
        {
            inV = inV.Replace("'NULL'", "null");
            inV = inV.Replace("'null'", "null");
            return inV;
        }

        /// <summary>
        /// Replaces '0' with null
        /// </summary>
        /// <param name="inV"></param>
        /// <returns></returns>
        public static string ReplaceZeroWithNulls(string inV)
        {
            return inV.Replace("'0'", "null");
        }

        /// <summary>
        /// Prefaces each line with Response.Write suitable for VBScript usage.
        /// </summary>
        /// <param name="linesOfText"></param>
        /// <returns></returns>
        public static string prefixCode(string[] linesOfText)
        {
            var sbr = new StringBuilder(1000);
            foreach (string Line in linesOfText)
            {
                string tmpLine = "Response.Write(\"" + Line.Replace(@"""", @"'") + "\")";
                sbr.AppendLine(tmpLine);
            }
            return sbr.ToString();
        }
    }
}